package com.yc.favorite.mapper;

import com.yc.favorite.entity.Favorite;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ly
 * @since 2023-10-24
 */
public interface FavoriteMapper extends BaseMapper<Favorite> {

    @Insert("insert into favorite values(default," +
            "#{flabel},#{furl},#{fdesc},#{ftags},#{uid})")
    @Options(useGeneratedKeys = true, keyColumn = "fid",
            keyProperty = "fid")
    int insert(Favorite favorite);

    @Select("select * from favorite where fid = #{id}")
    Favorite selectById(int id);

    @Select("select a.* from favorite a join tagfavorite b on a.fid=b.fid" +
            " where b.tid = #{tid}")
    List<Favorite> selectByTid(int tid);

    @Delete("delete from favorite where fid = #{fid}")
    void deleteById(int fid);

}
